<template>
  <div class="apply">
    <div class="table">
      <div style="padding-bottom: 27px">
        共计{{ count }}个,其中审核通过{{ yitongguo }}个，审核驳回{{
          weitongguo
        }}个,已提交(审核中){{ weishenhe }}个,未提交{{ weitijao }}个
      </div>
      <div>
        <el-input
          placeholder="搜索"
          v-model="input3"
          class="input-with-select"
          style="width: 300px"
        >
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="sousuo"
          ></el-button>
        </el-input>
        <el-button type="primary" style="margin: 0 20px" @click="daochu"
          >导出数据</el-button
        >
        <el-select
          v-model="status"
          style="width: 200px"
          placeholder="请选择"
          @change="check_list"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </div>
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        size="small"
        :header-cell-style="{ 'text-align': 'center' }"
        :cell-style="{ 'text-align': 'center' }"
        :highlight-current-row="aaa"
        width="100%;"
      >
        <el-table-column type="index" label="序号">
          <template scope="scope">
            <span>{{ (page - 1) * 15 + scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="com_name"
          label="单位名称"
          style="font-size: 18px"
        >
          <template slot-scope="scope">
            <div @click="tanchu(scope.row)">{{ scope.row.com_name }}</div>
          </template></el-table-column
        >
        <el-table-column prop="com_type" label="单位类型"></el-table-column>
        <el-table-column prop="com_type" label="审核状态">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 1">未提交</div>
            <!-- <div v-else-if="scope.row.status == 2">已提交(审核中)</div> -->
            <div v-else-if="scope.row.status == 2">已提交</div>
            <div v-else-if="scope.row.status == 3">审核通过</div>
            <div v-else-if="scope.row.status == 4">审核驳回</div>
          </template>
        </el-table-column>
        <el-table-column prop="is_shou" label="纸质材料">
          <template slot-scope="scope">
            <div v-if="scope.row.is_shou == 1">已收到</div>
            <div v-if="scope.row.is_shou == 2">未收到</div>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注"></el-table-column>
        <el-table-column prop="com_type" label="驳回原因">
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.reason" :key="index">
              {{ item.content }}
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column prop label="申报内容" style="heigth:50px">
          <template slot-scope="scope">
            <div>
              <div
                v-for="(item,index) in scope.row.award"
                :key="index"
              >{{item.award_name}},数量：{{item.num}}</div>
            </div>
          </template>
        </el-table-column>-->
        <!-- <el-table-column prop="is_allow" label="审核状态" @click="tupian">
          <template slot-scope="scope">
            <div v-if="scope.row.is_allow==1">通过</div>
            <div v-if="scope.row.is_allow==2">不通过</div>
            <div v-if="scope.row.is_allow==3">已提交</div>
            <div v-if="scope.row.is_allow==0">未提交</div>
          </template>
        </el-table-column>-->
        <el-table-column label="操作">
          <template slot-scope="scope">
            <div class="caozuos">
              <div>
                <el-button
                  type="primary"
                  size="mini"
                  icon="el-icon-share"
                  class="btn"
                  @click="tupian(scope.row)"
                  >查看</el-button
                >
                <el-button
                  type="primary"
                  size="mini"
                  icon="el-icon-share"
                  class="btn"
                  @click="handledetails(scope.row)"
                  >审核</el-button
                >
              </div>

              <div>
                <el-button
                  class="btn"
                  type="primary"
                  size="mini"
                  icon="el-icon-edit"
                  @click="handleput(scope.row)"
                  >驳回</el-button
                >
                <el-button
                  class="btn"
                  type="primary"
                  size="mini"
                  icon="el-icon-edit"
                  @click="handleputs(scope.row)"
                  >备注</el-button
                >
              </div>
              <div>
                <el-select
                  v-model="scope.row.is_shous"
                  placeholder="纸质材料"
                  @change="check_lists(scope.row)"
                >
                  <el-option label="已收到" value="1"></el-option>
                  <el-option label="未收到" value="2"></el-option>
                </el-select>
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- <el-dialog title="修改密码" :visible.sync="dialogFormVisible" width="30%">
      <el-form :model="form">
        <el-form-item label="旧密码" :label-width="formLabelWidth">
          <el-input v-model="form.mima" autocomplete="off" placeholder="请输入旧密码"></el-input>
        </el-form-item>
        <el-form-item prop="phones" label="新密码" :label-width="formLabelWidth">
          <el-input
            oninput="value=value.replace(/[\W]/g,'')"
            maxlength="20"
            type="password"
            v-model="form.password"
            placeholder="请输入密码"
          />
        </el-form-item>
        <el-form-item prop="phones" label="新密码" :label-width="formLabelWidth">
          <el-input
            oninput="value=value.replace(/[\W]/g,'')"
            maxlength="20"
            type="password"
            v-model="form.password1"
            placeholder="请再次输入密码"
            @blur="Verification"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>-->
    <div class="fenye">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="totalPage"
        :page-size="pageSize"
        :current-page="page"
        @current-change="handleSizeChange"
      ></el-pagination>
    </div>
    <el-dialog :visible.sync="centerDialogVisible" width="30%" center>
      <div class="tongguo">是否通过</div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="quedingtongguo">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="驳回意见"
      :visible.sync="centerDialogVisibles"
      width="30%"
      center
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="驳回原因" prop="desc">
          <el-input type="textarea" v-model="ruleForm.desc"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >确定</el-button
          >
          <el-button @click="resetForm('ruleForm')">取消</el-button>
        </el-form-item>
      </el-form>
      <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisibles = false">取 消</el-button>
        <el-button type="primary" @click="centerDialogVisibles = false">确 定</el-button>
      </span>-->
    </el-dialog>
    <el-dialog title="信息" :visible.sync="dialogVisible" width="40%">
      <div class="image">
        <img :src="src" alt />
      </div>
    </el-dialog>
    <el-dialog title="修改" :visible.sync="dialogXiugai" width="30%">
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        label-width="140px"
        class="demo-ruleForm"
      >
        <div v-for="(item, index) in award" :key="index">
          <el-form-item :label="item.award_name" prop="pass">
            <el-input
              type="Number"
              v-model="award[index].num"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </div>
        <el-form-item label="修改原因" prop="pass">
          <el-input type="text" v-model="reason" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogXiugai = false">取 消</el-button>
        <el-button type="primary" @click="queding">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="详情" :visible.sync="xiangqingVisible" width="30%" center>
      <div class="items">
        <div>联系人姓名</div>
        <div>{{ xiangqing1.user_name }}</div>
      </div>
      <div class="items">
        <div>部门</div>
        <div>{{ xiangqing1.branch }}</div>
      </div>
      <div class="items">
        <div>手机号</div>
        <div>{{ xiangqing1.mobile }}</div>
      </div>
      <div class="items">
        <div>邮箱</div>
        <div>{{ xiangqing1.email }}</div>
      </div>
      <div class="items">
        <div>注册时间</div>
        <div>{{ xiangqing1.create_time }}</div>
      </div>
      <div class="items">
        <div>修改原因</div>
        <div>
          <div v-for="(item, index) in xiangqing1.reason" :key="index">
            {{ item.reason }}
          </div>
        </div>
      </div>
      <!-- <div class="items">
        <div>联系人姓名</div>
        <div>{{xiangqing1.user_name}}</div>
      </div>-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="xiangqingVisible = false">取 消</el-button>
        <el-button type="primary" @click="xiangqingVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      title="详情"
      :visible.sync="xiangqingVisibles"
      width="30%"
      center
    >
      <div class="beizhus">
        <div>备注</div>
        <el-input type="textarea" v-model="remark"></el-input>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="xiangqingVisibles = false">取 消</el-button>
        <el-button type="primary" @click="quedings">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
Date.prototype.format = function (fmt) {
  var o = {
    "M+": this.getMonth() + 1, //月份
    "d+": this.getDate(), //日
    "h+": this.getHours(), //小时
    "m+": this.getMinutes(), //分
    "s+": this.getSeconds(), //秒
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
    S: this.getMilliseconds(), //毫秒
  };
  if (/(y+)/.test(fmt))
    fmt = fmt.replace(
      RegExp.$1,
      (this.getFullYear() + "").substr(4 - RegExp.$1.length)
    );
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt))
      fmt = fmt.replace(
        RegExp.$1,
        RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
      );
  return fmt;
};
import {
  check_list,
  refuse,
  pass,
  user_details_del,
  edit_user_details,
  award_details,
  submit_audit,
  turn_down,
  user_is_shou,
  user_remark,
} from "../axios/api";
export default {
  computed: {
    tableMaxHeight() {
      console.log(window.innerHeight - 400);
      return document.body.clientHeight - 400 + "px";
    },
  },

  data() {
    return {
      is_shou: "",
      tishi: "",
      obj: {},
      remark: "",
      xiangqingVisibles: false,
      status: "",
      centerDialogVisibles: false,
      group_id: sessionStorage.getItem("group_id"),
      is_gai: sessionStorage.getItem("is_gai"),
      reason: "",
      xiangqingVisible: false,
      xiangqing1: {},
      weitijao: 0,
      yitongguo: "0",
      input3: sessionStorage.getItem("inputs") || "",
      options: [
        {
          value: "1",
          label: "未提交",
        },
        {
          value: "2",
          label: "已提交(审核中)",
        },
        {
          value: "3",
          label: "审核通过",
        },
        {
          value: "4",
          label: "审核驳回",
        },
      ],
      com_name: "",
      weishenhe: 0,
      is_allow: "",
      dialogXiugai: false,
      dialogVisible: false,
      chageVisible: false,
      centerDialogVisible: false,
      aaa: true,
      page: sessionStorage.getItem("page") || 1,
      totalPage: 0,
      weitongguo: "0",
      count: 0,
      currentPage: 1,
      id: "",
      pageSize: 0,
      src: "",
      arr: [],
      formLabelWidth: "80px",
      award: [],
      form: {
        mima: "",
        password1: "",
        password: "",
      },
      dialogFormVisible: false,
      disabled: true,
      tableData: [],
      multipleSelection: [],
      ruleForm: {
        desc: "",
      },
      rules: {
        desc: [{ required: true, message: "请填写驳回意见", trigger: "blur" }],
      },
    };
  },
  created() {
    this.check_list();
  },
  components: {},

  methods: {
    com_names() {
      console.log(this.com_name);
      this.check_list();
    },
    is_allows() {
      console.log(this.is_allow);
      this.check_list();
    },
    xiangqing(e) {
      console.log(e);

      this.xiangqing1 = e;
      this.xiangqingVisible = true;
    },
    daochu() {
      console.log(window.location.host);
      window.location.href =
        "http://" +
        window.location.host +
        "/admin/user_export?token=" +
        sessionStorage.getItem("Token1") +
        "";
    },

    handleSizeChange(val) {
      console.log(val);
      this.page = val;
      sessionStorage.setItem("page", val);
      this.check_list();
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let params = {
            content: this.ruleForm.desc,
            token: sessionStorage.getItem("Token1"),
            com_id: this.delId,
          };
          turn_down(params).then((res) => {
            if (res.data.code == 200) {
              this.$message({
                message: "驳回成功",
                type: "success",
              });
              this.check_list();
              this.centerDialogVisibles = false;
            } else {
              this.$message.error(res.data.msg);
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    tanchu(e) {
      console.log(e);
    },
    submitForm1(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let params = {
            id: this.arr,
            token: sessionStorage.getItem("Token1"),
            content: this.ruleForm.desc,
          };
          refuse(params).then((res) => {
            this.arr = [];
            console.log(res);
            if (res.data.code == 200) {
              this.$message({
                message: "已驳回",
                type: "success",
              });
            } else {
              this.$message.error(res.data.msg);
            }
          });
          this.chageVisible = false;
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    handleputs(e) {
      this.obj = e;
      this.remark = "";
      this.xiangqingVisibles = true;
    },
    quedings() {
      let params = {
        id: this.obj.id,
        token: sessionStorage.getItem("Token1"),
        remark: this.remark,
      };
      user_remark(params).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.$message({
            message: "备注成功",
            type: "success",
          });
          this.xiangqingVisibles = false;
          this.check_list();
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.centerDialogVisibles = false;
    },
    // handleSizeChange(val) {
    //   console.log(`每页 ${val} 条`);
    // },
    // handleCurrentChange(val) {
    //   console.log(`当前页: ${val}`);
    //   this.page = val;
    //   this.check_list();
    // },
    sousuo() {
      this.check_list();
      sessionStorage.setItem("inputs", this.input3);
    },
    daochu() {
      console.log(window.location.host);
      // window.location.href =
      //   "http://" +
      //   window.location.host +
      //   "/common/user_award_export?token=" +
      //   sessionStorage.getItem("Token1") +
      //   "";
      window.location.href =
        "http://" +
        window.location.host +
        "/common/user_award_export?token=" +
        sessionStorage.getItem("Token1") +
        "";
    },
    check_list() {
      let params = {
        token: sessionStorage.getItem("Token1"),
        page: this.page,
        com_name: this.input3,
        is_allow: this.is_allow,
        status: this.status,
      };
      check_list(params).then((res) => {
        console.log(res);
        this.currentPage = res.data.data.page + 0;
        this.totalPage = res.data.data.totalPage + 0;
        console.log(res.data.data.weitongguo);
        console.log(res.data.data.yitongguo);
        if (res.data.data.weitongguo) {
          this.weitongguo = res.data.data.weitongguo;
        }
        if (res.data.data.yitongguo) {
          this.yitongguo = res.data.data.yitongguo;
        }
        if (res.data.data.count) {
          this.count = res.data.data.count;
        }
        if (res.data.data.weishenhe) {
          this.weishenhe = res.data.data.weishenhe;
        }
        if (res.data.data.weitijao) {
          this.weitijao = res.data.data.weitijao;
        }
        this.pageSize = parseInt(res.data.data.pageSize);
        console.log(this.pageSize);
        this.tableData = res.data.data.data;
        this.tableData.forEach((item) => {
          var myDate = new Date(item.create_time * 1000);
          myDate.setDate(myDate.getDate());
          console.log(myDate.setDate(myDate.getDate()));
          item.create_time = myDate.format("yyyy年MM月dd日");
        });
      });
    },
    Verification() {
      if (this.form.password.length >= 6) {
        if (this.form.password1 != this.form.password) {
          this.$message({
            message: "两次密码不一致请重新输入",
            type: "error",
          });
          this.form.password1 = "";
        }
      } else {
        this.form.password = "";
        this.form.password1 = "";
        this.$message({
          message: "密码最低为6位数",
          type: "error",
        });
      }
    },
    check_lists(e) {
      console.log(e);
      let params = {
        token: sessionStorage.getItem("Token1"),
        id: e.id,
        is_shou: e.is_shous,
      };
      user_is_shou(params).then((res) => {
        if ((res.data.code = 200)) {
          this.$message({
            message: "变更成功",
            type: "success",
          });
          this.check_list();
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    shenhe() {
      let params = {
        token: sessionStorage.getItem("Token1"),
        id: this.arr,
      };
      pass(params).then((res) => {
        console.log(res);
        this.arr = [];
        if (res.data.code == 200) {
          this.$message({
            message: "已批量通过",
            type: "success",
          });
        } else {
          this.$message({
            message: res.data.msg,
          });
        }
      });
    },
    quedingtongguo() {
      let arr = [];
      arr.push(this.id);
      let params = {
        token: sessionStorage.getItem("Token1"),
        id: arr,
      };
      console.log(params);
      pass(params).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.$message({
            message: "已通过",
            type: "success",
          });
        }
      });
      this.centerDialogVisible = false;
    },
    handledetails(e) {
      let params = {
        token: sessionStorage.getItem("Token1"),
        com_id: e.id,
      };
      submit_audit(params).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.$message({
            message: "提交成功",
            type: "success",
          });
          this.check_list();
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    handleput1() {
      this.ruleForm.desc = "";
      this.chageVisible = true;
    },
    handleput(e) {
      this.delId = e.id;
      this.centerDialogVisibles = true;
      // let params = {
      //   token: sessionStorage.getItem("Token1"),
      //   com_id: e.id,
      // };
      // turn_down(params).then((res) => {
      //   if (res.data.code == 200) {
      //     this.$message({
      //       message: "驳回成功",
      //       type: "success",
      //     });
      //     this.check_list();
      //   } else {
      //     this.$message.error(res.data.msg);
      //   }
      // });
    },
    tupian(e) {
      console.log(e);
      this.$router.push({ path: "/shenqing1", query: { id: e.id } });
    },
    handleput2(e) {
      this.award = e.award;
      this.id = e.id;
      this.dialogXiugai = true;
    },
    queding() {
      if (this.reason == "") {
        alert("填写修改原因");
      } else {
        this.dialogXiugai = false;
        console.log(this.award);
        let params = {
          token: sessionStorage.getItem("Token1"),
          data: this.award,
          reason: this.reason,
          user_id: this.id,
        };
        edit_user_details(params).then((res) => {
          console.log(res);
          if (res.data.code == 200) {
            this.$message({
              message: "修改成功",
              type: "success",
            });
            this.reason = "";
          } else {
            this.$message.error(res.data.msg);
          }
          this.check_list();
        });
      }
    },
    del() {
      console.log(this.arr);
      let params = {
        token: sessionStorage.getItem("Token1"),
        id: this.arr,
      };
      user_details_del(params).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.$message({
            message: "删除成功",
            type: "success",
          });
        } else {
          this.$message.error("删除失败");
        }
        this.check_list();
      });
    },
    handleDel(e) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let arr = [];
          arr.push(e.id);
          let params = {
            token: sessionStorage.getItem("Token1"),
            id: arr,
          };
          user_details_del(params).then((res) => {
            if (res.data.code == 200) {
              this.$message({
                message: "删除成功",
                type: "success",
              });
            } else {
              this.$message.error("删除失败");
            }
            this.check_list();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      console.log(val);
      val.forEach((item) => {
        this.arr.push(item.id);
      });
      this.arr = [...new Set(this.arr)];
      console.log(this.arr);

      if (val.length > 0) {
        this.disabled = false;
      } else {
        this.arr = [];
        this.disabled = true;
      }
      this.multipleSelection = val;
    },
  },
};
</script>

<style scoped>
.apply {
  width: 100%;
  height: 100%;
  background-color: #fff;
  overflow-x: scroll;
  overflow-y: scroll;
  /* overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between; */
}
.gongneng {
  display: flex;
  align-items: center;
}
.gongneng > div {
  margin: 0 10px;
}
.table {
  width: 100%;
  height: 80%;
  max-width: 100%;
  margin: 0 auto;
  overflow-x: scroll;
  position: relative;
  overflow: auto;
  overflow-y: scroll;
  box-sizing: border-box;
  padding: 30px;
}
.table::-webkit-scrollbar {
  display: none;
}
.apply::-webkit-scrollbar {
  display: none;
}
.caozuo {
  box-sizing: border-box;
  padding: 20px;
  display: flex;
  justify-content: space-between;
}
.fenye {
  width: 100%;
  height: 40px;

  display: flex;
  justify-content: center;
  align-items: center;
}
.btn {
  font-size: 12px;
}
.tongguo {
  display: flex;
  justify-content: center;
  align-items: center;
}
.image {
  width: 100%;
}
.image > img {
  display: block;
  margin: 0 auto;
  width: 100%;
  height: auto;
}
/* .table::-webkit-scrollbar {
  display: none;
} */
.item {
  /* display: flex; */
  flex-direction: column;
  justify-content: space-between;
  margin-bottom: 10px;
}
.items {
  width: 100%;
  font-size: 20px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #eee;
  padding: 10px;
}
.caozuos {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.beizhus {
  display: flex;
  align-items: center;
}
.beizhus > div:nth-child(1) {
  flex: 0 0 80px;
}
</style>